package com.bjsxt.search.controller;

import com.bjsxt.search.service.SolrService;
import com.bjsxt.utils.Result;
import com.bjsxt.utils.SolrDocument;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/search")
public class SolrController {

    @Autowired
    private SolrService solrService;

    /**
     * 向solr索引库中导入数据
     * @return
     */
    @RequestMapping("/importAll")
    public Result importAll(){

        return this.solrService.importAll();
    }

   @RequestMapping("/list")
   public List<SolrDocument> selectByq(String q,@RequestParam(defaultValue = "1") Long page,@RequestParam(defaultValue = "10") Integer pageSize){


       try {
           return this.solrService.selectByq(q,page,pageSize);
       } catch (Exception e) {
           e.printStackTrace();
       }
       return null;
   }

}
